home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / edit / thesrc20.zip / reserved.c < prev    next >
C/C++ Source or Header  |  1995-01-26  |  6KB  |  194 lines

  1. /***********************************************************************/
  2. /* RESERVED.C -                                                        */
  3. /* This file contains funtions related to reserved lines.              */
  4. /***********************************************************************/
  5. /*
  6.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  7.  * Copyright (C) 1991-1995 Mark Hessling
  8.  *
  9.  * This program is free software; you can redistribute it and/or
  10.  * modify it under the terms of the GNU General Public License as
  11.  * published by the Free Software Foundation; either version 2 of
  12.  * the License, or any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17.  * General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to:
  21.  *
  22.  *    The Free Software Foundation, Inc.
  23.  *    675 Mass Ave,
  24.  *    Cambridge, MA 02139 USA.
  25.  *
  26.  *
  27.  * If you make modifications to this software that you feel increases
  28.  * it usefulness for the rest of the community, please email the
  29.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  30.  * This software is going to be maintained and enhanced as deemed
  31.  * necessary by the community.
  32.  *
  33.  * Mark Hessling                     email: M.Hessling@gu.edu.au
  34.  * 36 David Road                     Phone: +61 7 849 7731
  35.  * Holland Park                      Fax:   +61 7 875 5314
  36.  * QLD 4121
  37.  * Australia
  38.  */
  39.  
  40. /*
  41. $Id: reserved.c 2.0 1995/01/26 16:31:54 MH Release MH $
  42. */
  43.  
  44. #include <stdio.h>
  45.  
  46. #include "the.h"
  47. #include "proto.h"
  48. /***********************************************************************/
  49. #ifdef PROTO
  50. short add_reserved_line(CHARTYPE *spec,CHARTYPE *line,short base,short off,COLOUR_ATTR *attr)
  51. #else
  52. short add_reserved_line(spec,line,base,off,attr)
  53. CHARTYPE *spec,*line;
  54. short base;
  55. short off;
  56. COLOUR_ATTR *attr;
  57. #endif
  58. /***********************************************************************/
  59. {
  60. /*-------------------------- external data ----------------------------*/
  61. /*--------------------------- local data ------------------------------*/
  62.  RESERVED *curr=NULL;
  63.  CHARTYPE *templine=line;
  64. /*--------------------------- processing ------------------------------*/
  65. #ifdef TRACE
  66.  trace_function("reserved.c:add_reserved_line");
  67. #endif
  68. /*---------------------------------------------------------------------*/
  69. /* First check if the row already has a reserved line on it...         */
  70. /*---------------------------------------------------------------------*/
  71.  if ((curr = find_reserved_line(FALSE,0,base,off)) != NULL)
  72.     delete_reserved_line(base,off);
  73.  curr = rll_add(CURRENT_FILE->first_reserved,CURRENT_FILE->first_reserved,sizeof(RESERVED));
  74.  if (CURRENT_FILE->first_reserved == NULL)
  75.     CURRENT_FILE->first_reserved = curr;
  76.  if (templine == NULL)
  77.     templine = "";
  78.  if ((curr->line = (CHARTYPE *)(*the_malloc)((strlen(templine)+1)*sizeof(CHARTYPE))) == NULL)
  79.    {
  80.     display_error(30,"",FALSE);
  81. #ifdef TRACE
  82.     trace_return();
  83. #endif
  84.     return(RC_OUT_OF_MEMORY);
  85.    }
  86.  if ((curr->spec = (CHARTYPE *)(*the_malloc)((strlen(spec)+1)*sizeof(CHARTYPE))) == NULL)
  87.    {
  88.     display_error(30,"",FALSE);
  89. #ifdef TRACE
  90.     trace_return();
  91. #endif
  92.     return(RC_OUT_OF_MEMORY);
  93.    }
  94.  if ((curr->attr = (COLOUR_ATTR *)(*the_malloc)(sizeof(COLOUR_ATTR))) == NULL)
  95.    {
  96.     display_error(30,"",FALSE);
  97. #ifdef TRACE
  98.     trace_return();
  99. #endif
  100.     return(RC_OUT_OF_MEMORY);
  101.    }
  102.  strcpy(curr->line,templine);
  103.  strcpy(curr->spec,spec);
  104.  curr->length = strlen(templine);
  105.  curr->base = base;
  106.  curr->off = off;
  107.  memcpy(curr->attr,attr,sizeof(COLOUR_ATTR));
  108. #ifdef TRACE
  109.  trace_return();
  110. #endif
  111.  return(RC_OK);
  112. }
  113. /***********************************************************************/
  114. #ifdef PROTO
  115. RESERVED *find_reserved_line(bool find_by_row,ROWTYPE row,short base,short off)
  116. #else
  117. RESERVED *find_reserved_line(find_by_row,row,base,off)
  118. bool find_by_row;
  119. ROWTYPE row;
  120. short base,off;
  121. #endif
  122. /***********************************************************************/
  123. {
  124. /*-------------------------- external data ----------------------------*/
  125. /*--------------------------- local data ------------------------------*/
  126.  RESERVED *curr=CURRENT_FILE->first_reserved;
  127. /*--------------------------- processing ------------------------------*/
  128. #ifdef TRACE
  129.  trace_function("reserved.c:find_reserved_line");
  130. #endif
  131.  while(curr != NULL)
  132.    {
  133.     if (find_by_row)
  134.       {
  135.        if (curr->base == POSITION_TOP
  136.        &&  row == curr->off-1)
  137.           break;
  138.        if (curr->base == POSITION_BOTTOM
  139.        &&  row == (curr->off+CURRENT_SCREEN.rows[WINDOW_MAIN]))
  140.           break;
  141.        if (curr->base == POSITION_MIDDLE
  142.        &&  row == (curr->off+(CURRENT_SCREEN.rows[WINDOW_MAIN]/2))-1)
  143.           break;
  144.       }
  145.     else
  146.       {
  147.        if (curr->base == base
  148.        &&  curr->off == off)
  149.           break;
  150.       }
  151.     curr = curr->next;
  152.    }
  153. #ifdef TRACE
  154.  trace_return();
  155. #endif
  156.  return(curr);
  157. }
  158. /***********************************************************************/
  159. #ifdef PROTO
  160. short delete_reserved_line(short base,short off)
  161. #else
  162. short delete_reserved_line(base,off)
  163. short base,off;
  164. #endif
  165. /***********************************************************************/
  166. {
  167. /*-------------------------- external data ----------------------------*/
  168. /*--------------------------- local data ------------------------------*/
  169.  RESERVED *curr=NULL;
  170. /*--------------------------- processing ------------------------------*/
  171. #ifdef TRACE
  172.  trace_function("reserved.c:delete_reserved_line");
  173. #endif
  174.  if ((curr = find_reserved_line(FALSE,0,base,off)) == NULL)
  175.    {
  176.     display_error(64,"",FALSE);
  177. #ifdef TRACE
  178.     trace_return();
  179. #endif
  180.     return(RC_NO_LINES_CHANGED);
  181.    }
  182.  if (curr->line != NULL)
  183.     (*the_free)(curr->line);
  184.  if (curr->spec != NULL)
  185.     (*the_free)(curr->spec);
  186.  if (curr->attr != NULL)
  187.     (*the_free)(curr->attr);
  188.  rll_del(&CURRENT_FILE->first_reserved,NULL,curr,DIRECTION_FORWARD);
  189. #ifdef TRACE
  190.  trace_return();
  191. #endif
  192.  return(RC_OK);
  193. }
  194.